﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;

namespace CPAScoringPerformanceTester.TestTask
{
    /// <summary>
    /// ServiceConnectionTaskWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ServiceConnectionTaskWindow : Window, INotifyPropertyChanged
    {
        private int repeatCount;
        public int RepeatCount
        {
            get { return repeatCount; }
            set
            {
                if (value == repeatCount || repeatCount < 0) return;
                repeatCount = value;
                OnPropertyChanged("RepeatCount");
            }
        }

        public RelayCommand ApplyCommand { get; set; }
        public RelayCommand CloseCommand { get; set; }
        public event PropertyChangedEventHandler PropertyChanged;

        public ServiceConnectionTaskWindow()
        {
            CloseCommand = new RelayCommand(() => this.Close());
            ApplyCommand = new RelayCommand(Apply);
            InitializeComponent();
            RepeatCount = ServiceConnectionSettings.Instance.RepeatCount;
        }

        private void Apply()
        {
            ServiceConnectionSettings.Instance.RepeatCount = RepeatCount;
            this.Close();
        }

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
